﻿define('logger', ['system'], function(system) {

    var buildMessage = function (type, message) {
        var div = $("<div>");
        div.addClass("alert");
        div.addClass("alert-" + type);
        div.html(message);
        var bt = $("<button>");
        bt.addClass("close");
        bt.attr("data-dismiss", "alert");
        bt.html("×");
        div.prepend(bt);
        return div;
    };
    
    var cont = $("#notify");

    var log = function (message, data, source, notify, messageType) {
        source = source ? '[' + source + '] ' : '';
        if (data) {
            system.log(source, message, data);
        } else {
            system.log(source, message);
        }
        if (notify !== false) {
            flushMessage(buildMessage(messageType, message));
        }
    };

    var flushMessage = function(message) {
        cont.append(message);
        message.hide();
        message.fadeIn();
        setTimeout(function() {
            message.fadeOut(function() {
                message.remove();
            });
        }, 2500);
    };

    return {
        success: function (message, notify, data, source) {
            log(message, data, source, notify, 'success');
        },
        error: function (message, notify, data, source) {
            log(message, data, source, notify, 'error');
        },
        info: function (message, notify, data, source) {
            log(message, data, source, notify, 'info');
        }
    };
});